//
//  KC_DETAIL_VC.m
//  Jade
//
//  Created by king on 16/4/7.
//  Copyright © 2016年 KC. All rights reserved.
//

#import "KC_DETAIL_VC.h"

@interface KC_DETAIL_VC ()<UIGestureRecognizerDelegate>

/** 返回按钮 */
@property (nonatomic,strong)UIButton *backBtn;

@property (nonatomic,strong)UIButton *shareBtn;

@end

@implementation KC_DETAIL_VC

#pragma mark - LifeCycle

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];

}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _backBtn.frame = CGRectMake(10, self.navigationHeight - 35, 100, 30);
    [_backBtn setImage:[UIImage imageNamed:@"only_back"] forState:UIControlStateNormal];
    [_backBtn addTarget:self action:@selector(backNavAction) forControlEvents:UIControlEventTouchUpInside];
    _backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 70);
    [self.KCNavView addSubview:_backBtn];
    
    _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_shareBtn setImage:[UIImage imageNamed:@"dshare"] forState:UIControlStateNormal];
    _shareBtn.frame = CGRectMake(SCREEN_WIDTH - 60, 32, 60, 24);
    _shareBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 25, 0, 10);
    _shareBtn.titleLabel.font = SYSTEM_FONT(FONTS_12 + FONT_NUM);
    [_shareBtn addTarget:self action:@selector(share)forControlEvents:UIControlEventTouchUpInside];
    _shareBtn.hidden = YES;
    [self.KCNavView addSubview:_shareBtn];
    
    
//    全屏返回
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    panGesture.delegate = self;
    [self.view addGestureRecognizer:panGesture];
    
}

#pragma mark -Actions

- (void)backNavAction {
    [self.navigationController popViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)HideBack{
    _backBtn.hidden = YES;
}

- (UIImage *)imageWithImage:(UIImage *)image{
    
    UIGraphicsBeginImageContext(CGSizeMake(300, 300));
    [image drawInRect:CGRectMake(0,0,300,300)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *data = UIImageJPEGRepresentation(newImage, 0.1);
    return [UIImage imageWithData:data];

}


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    
    if(self.navigationController.childViewControllers.count == 1)
    {
        return NO;
    }
    
    return YES;
}

@end
